﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Company_CheckBidPwd : System.Web.UI.Page, IAccess
{
    /// <summary>
    /// 执行行为
    /// </summary>
    string action = string.Empty;
    string returnurl = string.Empty;
    string action2 = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        CurrentAccount.CheckSessionTimeOut(this);

        Page.Form.DefaultButton = btnSubmit.UniqueID;
        if (string.IsNullOrEmpty(CurrentAccount.Company_Project_Switch.BidPassword)) // 没有设置密码 直接进入设置密码
        {
            Response.Redirect("ConfirmBidPassword.aspx");

        }

        //if (!CurrentProject.IsBidSwitch)
        //{
        //    HZ.Web.MessageBox.Show("报价开关未开启，无法确认报价。");
        //}

        //if (CurrentProject.InBidTime < 0)
        //{
        //    HZ.Web.MessageBox.Show("报价时间未到，请稍后再试！");
        //}

        //if (CurrentProject.InBidTime > 0)
        //{
        //    HZ.Web.MessageBox.Show("报价时间已过，无法确认报价！");
        //}

        action = (Request.QueryString["action"] ?? string.Empty).ToLower();
        action2 = (Request.QueryString["action2"] ?? string.Empty).ToLower();
        returnurl = (Request.QueryString["returnurl"] ?? string.Empty).ToLower();
        if (!IsPostBack)
        {
            HZ.BidSystem.BLL.BLL_Cache.SetOnlineModel(CurrentAccount.Account.AccountId.Value, new HZ.BidSystem.Model.OnLineModel() { Active = "正在输入报价密码" });

            if (action2 != null && action2 != "")
            {
                lblBidPriceStatus.Text = "注意：确认报价后，将无法再修改报价。";
                lblBidPriceStatus.Visible = true;
            }
            else
            {
                lblBidPriceStatus.Visible = false;
            }

        }

    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        //Page.Validate();
        //if (Page.IsValid)
        //{
        string bidpwd = txtBidPwd.Text.Trim();
        string randpwd = CurrentAccount.Account.AccountName.ToUpper();

        if (BLL_Factory.IBLL_Company.CheckBidPwd(bidpwd, randpwd, CurrentAccount.Account.AccountId.Value, CurrentAccount.ProjectId) == 1)
        {
            CurrentAccount.BidPwd = bidpwd;
            CurrentAccount.RandPwd = randpwd;


            // 跳转优先级
            if (returnurl != null && returnurl != "")
            {
                Response.Redirect(returnurl);
            }

            // 确认报价行为
            if (action2 == "confirmbid")
            {

                if (!CurrentProject.IsBidSwitch)
                {
                    HZ.Web.MessageBox.Show("报价开关未开启，无法确认报价。");
                }

                if (CurrentProject.InBidTime < 0)
                {
                    HZ.Web.MessageBox.Show("报价时间未到，请稍后再试！");
                }

                if (CurrentProject.InBidTime > 0)
                {
                    HZ.Web.MessageBox.Show("报价时间已过，无法确认报价！");
                }

                if (!(CurrentAccount.Company_Project_Switch.ConfirmStatus ?? false))
                {
                    // 记录确认日志
                    HZ.Common.log4netManager.LogInfo("确认报价", string.Format("确认报价成功:确认用户{0},操作IP{1}。", CurrentAccount.Account.AccountName, HZ.Fun.GetClientIP()), null);
                    BLL_Factory.IBLL_Company.ConfirmBid(CurrentAccount.Account.AccountId.Value, CurrentAccount.ProjectId);
                    BLL_Factory.IBLL_Company.ConfirmBid2(CurrentAccount.Account.AccountId.Value, CurrentAccount.ProjectId);
                }
                switch (action)
                {
                    case "bargain":
                        Response.Redirect(string.Format("~/Company/PrePrintPrice.aspx?action={0}", action));
                        break;
                    case "compete":
                        Response.Redirect(string.Format("~/Company/PrePrintPrice.aspx?action={0}", action));
                        break;
                    default:
                        Response.Redirect(string.Format("~/Company/PrePrintPrice.aspx?action={0}", action));
                        break;
                }
            }
            else
            {
                switch (action)
                {
                    case "bargain":
                        Response.Redirect(string.Format("~/Company/BargainPrice.aspx?action={0}", action));
                        break;
                    case "compete":
                        Response.Redirect(string.Format("~/Company/CompetePrice.aspx?action={0}", action));
                        break;
                    default:
                        Response.Redirect(string.Format("~/Company/BidPrice.aspx?action={0}", action));
                        break;
                }
            }
        }
        else
        {
            HZ.Web.MessageBox.Show("报价密码不正确");
        }

        //}
        //else
        //{
        //    HZ.Web.MessageBox.Show("客户端验证不成功");
        //}



    }
    #region IAccess Members

    IList<EnumAccess> IAccess.AccessList
    {
        get
        {
            var list = new List<EnumAccess>();
            list.Add(EnumAccess.Company);
            return list;
        }

    }

    #endregion
}
